home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 79 / maccd 79.iso / multimedial / GL Tron / Source / gltron / fonts.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-13  |  1.1 KB  |  58 lines  |  [TEXT/CWIE]

  1. #include "gltron.h"
  2.  
  3. char *gameDefault;
  4. void initFonts() {
  5.   char *path;
  6.   FILE *f;
  7.   char buf[100];
  8.   char gamefont[100];
  9.   char guifont[100];
  10.   char *game = NULL, *gui = NULL;
  11.  
  12.   if(gameFtx != NULL) ftxUnloadFont(gameFtx);
  13.   if(guiFtx != NULL) ftxUnloadFont(guiFtx);
  14.  
  15.   path = getFullPath("fonts.txt");
  16.   if(path != NULL) {
  17.     f = fopen(path, "r");
  18.     while(fgets(buf, sizeof(buf), f) != NULL) {
  19.       if(sscanf(buf, "game: %s ", gamefont) == 1)
  20.     game = gamefont;
  21.       else if(sscanf(buf, "menu: %s ", guifont) == 1)
  22.     gui = guifont;
  23.     }
  24.     fclose(f);
  25.     free(path);
  26.   } else {
  27.     fprintf(stderr, "can't load fonts.txt\n");
  28.     exit(1);
  29.   }
  30.  
  31.   if(game == NULL || gui == NULL) {
  32.     fprintf(stderr, "incomplete font definition in fonts.txt\n");
  33.     exit(1);
  34.   }
  35.  
  36.   gameFtx = ftxLoadFont(game);
  37.   guiFtx = ftxLoadFont(gui);
  38.  
  39.   if(gameFtx == NULL) {
  40.     fprintf(stderr, "can't load font %s\n", game);
  41.     exit(1);
  42.   }
  43.  
  44.   if(guiFtx == NULL) {
  45.     fprintf(stderr, "can't load font %s\n", gui);
  46.     exit(1);
  47.   }
  48. }
  49.  
  50. void deleteFonts() {
  51.   if(gameFtx != NULL)
  52.     ftxUnloadFont(gameFtx);
  53.   gameFtx = NULL;
  54.   if(guiFtx != NULL)
  55.     ftxUnloadFont(guiFtx);
  56.   guiFtx = NULL;
  57. }
  58.